<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>
<script type="text/javascript">
//    function setData(targetElement, targetElmentValue, targetElementLabel, targetElementLabelValue, myDialog){
//        $(myDialog).dialog("close");
//        document.getElementById(targetElement).value = targetElmentValue;
//        document.getElementById(targetElementLabel).value = targetElementLabelValue;
//        }
    
    $(document).ready(function(){
        $('#cb_ShipperAddressLocationID').change(function(){
            var valLoc = $('#cb_ShipperAddressLocationID').val();
            $.ajax ({
            type:"POST",
            url:"<?php echo Yii::app()->createUrl('/specialajax/getlocation'); ?>",
            data:"locationID="+valLoc,
            dataType:"json",
                success:function(data){        
                    var ZipCode = data[0].ZipCode;
                    $('#txt_ShipperAddressLocationIDZipCode').val(ZipCode);
                }
            });
        });
        
        $('#cb_ReceiverAddressLocationID').change(function(){
            var valLoc = $('#cb_ReceiverAddressLocationID').val();
            $.ajax ({
            type:"POST",
            url:"<?php echo Yii::app()->createUrl('/specialajax/getlocation'); ?>",
            data:"locationID="+valLoc,
            dataType:"json",
                success:function(data){        
                    var ZipCode = data[0].ZipCode;
                    $('#txt_ReceiverAddressLocationIDZipCode').val(ZipCode);
                }
            });
        });
        
        $('#cb_ItemShippingTypeID').change(function(){
            var sTypeID = $('#cb_ItemShippingTypeID').val();
            $.ajax ({
            type:"POST",
            url:"<?php echo Yii::app()->createUrl('/specialajax/getshippingtype'); ?>",
            data:"ItemShippingTypeID="+sTypeID,
            dataType:"json",
                success:function(data){        
                    var Cost = data[0].Cost;
                    $('#txt_BiayaKirim').val(Cost);
                    setTotalAmount();
                }
            });
        });
        $('#cb_ItemPackingID').change(function(){
            var sPackID = $('#cb_ItemPackingID').val();
            
             $.ajax ({
            type:"POST",
            url:"<?php echo Yii::app()->createUrl('/specialajax/getpacking'); ?>",
            data:"PackingID="+sPackID,
            dataType:"json",
                success:function(data){        
                    var PackingCost = data[0].PackingCost;

                    $('#txt_BiayaPacking').val(PackingCost);
                    setTotalAmount();
                }
            });
        });
        $('#cb_InsuranceNumber').change(function(){
            var insNum = $('#cb_InsuranceNumber').val();
            $.ajax ({
            type:"POST",
            url:"<?php echo Yii::app()->createUrl('/specialajax/getasuransi'); ?>",
            data:"InsuranceNumber="+insNum,
            dataType:"json",
                success:function(data){        
                        var InsuranceCost = data[0].InsuranceCost;
                        var AdministrationFee = data[0].AdministrationFee;
                        
                        $('#txt_BiayaAsuransi').val(InsuranceCost);
                        $('#txt_AdmAsuransi').val(AdministrationFee);
                        setTotalAmount();
                }
            });
        });
        $("#txt_OtherFee").change(function(){
            setTotalAmount();
        });
        $("#txt_AdministrationFee").change(function(){
            setTotalAmount();
        });
        $("#txt_TaxAmount").change(function(){
            setTotalAmount();
        });
    });
 
    function setTotalAmount(){
        var biayakirim = parseInt($('#txt_BiayaKirim').val().trim()==""?0:$('#txt_BiayaKirim').val());
        var biayapacking = parseInt($('#txt_BiayaPacking').val().trim()==""?0:$('#txt_BiayaPacking').val());
        var biayaasuransi = parseInt($('#txt_BiayaAsuransi').val().trim()==""?0:$('#txt_BiayaAsuransi').val());
        var biayaAdminasuransi = parseInt($('#txt_AdmAsuransi').val().trim()==""?0:$('#txt_AdmAsuransi').val());
        var OtherFee = parseInt($('#txt_OtherFee').val().trim()==""?0:$('#txt_OtherFee').val());

        $('#txt_TotalAmount').val(biayakirim + biayapacking + biayaasuransi + biayaAdminasuransi + OtherFee);
    }
</script>

<style type="text/css">
    table{
        border: 0px solid black;
        table-layout: fixed;
        width: 200%;
    }

    th, td {
        vertical-align: top;
        border: 1px solid black;
        overflow: hidden;
        /*width: 100px;*/
        max-width: 100px;
        /*overflow: hidden;*/
        text-overflow: ellipsis;
        white-space: nowrap;
    }
</style>

<?php Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker') ?> 
<?php
/* @var $this OdsregistrationformController */
/* @var $model Odsregistrationform */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'odsregistrationform-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>
 <table border="1" style="vertical-align:top;" width="200">
        <tr>
            <td colspan="6" style="text-align:center"><b>PENGIRIM : </b></td>
            <td colspan="6" style="text-align:center"><b>PENERIMA : </b></td>
            <td colspan="2">
                <?php echo $form->labelEx($model,'RegistrationID'); ?>
            </td>
        </tr>

        <tr>
            <td><?php echo $form->labelEx($mShipperHuman,'Name'); ?></td>
            <td colspan="5">: <?php echo CHtml::activeTextField($mShipperHuman, 'Name',array('size'=>70, 'tabIndex'=>1)) ?></td>
            <!-- <td><?php //echo $form->error($mShipperHuman,'Name'); ?></td> -->

            <td><?php echo $form->labelEx($mReceiverHuman,'Name'); ?></td>
            <td colspan="5">: <?php echo CHtml::activeTextField($mReceiverHuman, 'Name',array('size'=>70, 'tabIndex'=>6)) ?></td>
            <!-- <td><?php //echo $form->error($mReceiverHuman,'Name'); ?></td> -->

            <td colspan="2">
                <?php echo CHtml::activeNumberField($model,'RegistrationID',array('id' => 'txt_RegistrationID', 'size'=>20, 'value'=>'Generate By System', 'readonly'=>true)); ?>
            </td>
            <!-- <td><?php //echo $form->error($model,'InsuranceNumber'); ?> -->
        </tr>

        <tr>
            <td><?php echo $form->labelEx($mShipperHumanAtt,'Address'); ?></td>
            <td colspan="5">: <?php echo CHtml::activeTextArea($mShipperHumanAtt, 'Address',array('cols'=>58, 'rows'=>'5', 'tabIndex'=>2)) ?></td>
            <!-- <td><?php //echo $form->error($mShipperHumanAtt,'Address'); ?></td> -->

            <td><?php echo $form->labelEx($mReceiverHumanAtt,'Address'); ?></td>
            <td colspan="5">: <?php echo CHtml::activeTextArea($mReceiverHumanAtt, 'Address',array('cols'=>58, 'rows'=>'5', 'tabIndex'=>7)) ?></td>
            <!-- <td><?php //echo $form->error($mReceiverHumanAtt,'Address'); ?></td> -->

            <td colspan="2">
                <?php echo $form->labelEx($model,'PaymentTypeID'); ?>
                <?php
                $arrPayType = Masterpaymenttype::model()->findAll("isActive = 1");
                $dPayType = array();
                foreach ($arrPayType as $pType){
                    $dPayType[$pType->PaymentTypeID] = $pType->PaymentTypeName;
                }
                echo CHtml::activeDropDownList($model, 'PaymentTypeID', $dPayType, array('style'=>'width: 90px','tabIndex'=>10,));
                ?>
            </td>
        </tr>

        <tr>
            <td><?php echo $form->labelEx($mShipperLocation,'ZipCode') ?></td>
            <td>: <?php echo CHtml::activeTextField($mShipperLocation, 'ZipCode', array('id'=>'txt_ShipperAddressLocationIDZipCode', 'readonly'=>'true', 'Size' =>8, 'tabIndex'=>3)) ?></td>
            <!-- <td><?php //echo $form->error($mShipperLocation,'ZipCode'); ?></td> -->

            <td><?php echo $form->labelEx($mShipperHumanAtt,'PhoneNumber'); ?></td>
            <td>: <?php echo CHtml::activeTextField($mShipperHumanAtt, 'PhoneNumber',array('tabIndex'=>4, 'Size' =>8)) ?></td>
            <!-- <td><?php //echo $form->error($mShipperHumanAtt,'PhoneNumber'); ?></td> -->

            <td><?php echo $form->labelEx($mShipperHumanAtt,'AddressLocationID'); ?></td>
            <td>
                <?php
                $arrSLoc = ShipperLocation::model()->findAll("isActive = 1");
                $dShipperHumanAtt = array();
                $dShipperHumanAtt[0]= 'SELECT';
                foreach ($arrSLoc as $sLoc){
                    $Reg = Gfregency::model()->find("RegencyID = '$sLoc->RegencyID' and isActive = 1");
                    $dShipperHumanAtt[$sLoc->LocationID] = $Reg->RegencyName;
                }
                echo CHtml::activeDropDownList($mShipperHumanAtt, 'AddressLocationID', $dShipperHumanAtt, array('id'=>'cb_ShipperAddressLocationID','style'=>'width: 90px','tabIndex'=>5,));
                ?>
            </td>
            <!-- <td><?php //echo $form->error($mShipperHumanAtt,'AddressLocationID'); ?></td> -->

            <td><?php echo $form->labelEx($mReceiverLocation,'ZipCode') ?></td>
            <td>: <?php echo CHtml::activeTextField($mReceiverLocation, 'ZipCode', array('id'=>'txt_ReceiverAddressLocationIDZipCode','readonly'=>'true', 'Size' =>8,'tabIndex'=>8)) ?></td>
            <!-- <td><?php //echo $form->error($mReceiverLocation,'ZipCode'); ?></td> -->

            <td><?php echo $form->labelEx($mReceiverHumanAtt,'PhoneNumber'); ?></td>
            <td>: <?php echo CHtml::activeTextField($mReceiverHumanAtt, 'PhoneNumber',array('Size' =>8, 'tabIndex'=>9)) ?></td>
            <!-- <td><?php //echo $form->error($mReceiverHumanAtt,'PhoneNumber'); ?></td> -->

            <td><?php echo $form->labelEx($mReceiverHumanAtt,'AddressLocationID', array('onclick'=>'$("#myDialog_ReceiverAddressLocationID").dialog("open"); return false;',)); ?></td>
            <td><?php
                $arrRLoc = ShipperLocation::model()->findAll("isActive = 1");
                $dReceiverHumanAtt = array();
                $dReceiverHumanAtt[0]= 'SELECT';
                foreach ($arrRLoc as $rLoc){
                    $Reg = Gfregency::model()->find("RegencyID = '$rLoc->RegencyID' and isActive = 1");
                    $dReceiverHumanAtt[$rLoc->LocationID] = $Reg->RegencyName;
                }
                echo CHtml::activeDropDownList($mReceiverHumanAtt, 'AddressLocationID', $dReceiverHumanAtt, array('id' => 'cb_ReceiverAddressLocationID', 'style'=>'width: 90px','tabIndex'=>9,));
                ?>
            </td>
            <!-- <td><?php //echo $form->error($mReceiverHumanAtt,'AddressLocationID'); ?></td> -->

            <td colspan="2">
                
            </td>
            <!-- <td><?php //echo $form->error($model,'PaymentTypeID'); ?></td> -->
        </tr>

        <tr>
            <td colspan="5"><?php echo $form->labelEx($itemDetail,'ItemName'); ?></td>
            <td><?php echo $form->labelEx($model,'TotalItemsDetail'); ?></td>
            <td colspan="2"><?php echo $form->labelEx($itemDetail,'ItemWeightReal'); ?></td>
            <td colspan="2"><?php echo $form->labelEx($itemDetail,'ItemWeight'); ?></td>
            <td colspan="2"><?php echo $form->labelEx($itemDetail,'ItemDimension'); ?></td>
            <td colspan="2" rowspan="2"></td>
        </tr>

        <tr>
            <td colspan="5"><?php echo CHtml::activeTextArea($itemDetail,'ItemName',array('id' => 'txt_ItemName', 'Cols'=>25, 'Rows'=>3,'tabIndex'=>11)); ?></td>
            <!-- <td><?php //echo $form->error($itemDetail,'ItemName'); ?></td> -->

            <td><?php echo CHtml::activeNumberField($model,'TotalItemsDetail',array('id' => 'txt_TotalItemsDetail', 'size'=>8,'tabIndex'=>12)); ?></td>
            <!-- <td><?php //echo $form->error($model,'TotalItemsDetail'); ?></td> -->

            <td colspan="2">
                <?php echo CHtml::activeNumberField($itemDetail,'ItemWeightReal',array('id' => 'txt_ItemWeightReal', 'size'=>11,'tabIndex'=>13)); ?>
                <?php
                $arrMeasurementReal = GfmeasurementunitWeightReal::model()->findAll("isActive = 1");
                $dMeReal = array();
                foreach ($arrMeasurementReal as $mReal){
                    $dMeReal[$mReal->MeasurementUnitID] = $mReal->MeasurementUnitNameShort;
                }
                echo CHtml::activeDropDownList($itemDetail, 'ItemMeasurementUnitIDReal', $dMeReal, array('style'=>'width: 60px','tabIndex'=>14,));
                ?>
            </td>
            <!-- <td><?php //echo $form->error($itemDetail,'ItemWeightReal'); ?></td> -->

            <td colspan="2"><?php echo CHtml::activeNumberField($itemDetail,'ItemWeight',array('id' => 'txt_ItemWeight', 'size'=>11,'tabIndex'=>14)); ?>
                <?php
                $arrMeasurement = GfmeasurementunitWeight::model()->findAll("isActive = 1");
                $dMe = array();
                foreach ($arrMeasurement as $me){
                    $dMe[$me->MeasurementUnitID] = $me->MeasurementUnitNameShort;
                }
                echo CHtml::activeDropDownList($itemDetail, 'ItemMeasurementUnitID', $dMe, array('style'=>'width: 60px','tabIndex'=>15,));
                ?>
            </td>
            <!-- <td><?php //echo $form->error($itemDetail,'ItemWeight'); ?></td> -->

            <td colspan="2"><?php echo CHtml::activeTextField($itemDetail,'ItemDimension',array('id' => 'txt_ItemDimension','size'=>20,'maxlength'=>50,'tabIndex'=>15)); ?></td>
            <!-- <td><?php //echo $form->error($itemDetail,'ItemDimension'); ?></td> -->
        </tr>

        <tr>
            <td colspan="12" bgcolor="black" style="text-align:center;vertical-align:middle"><p style="color:white">ISI BARANG TIDAK DIPERIKSA</p></td>
            <td><label>Biaya Kirim</label></td>
            <td>: <input type="text" id = "txt_BiayaKirim" style="border: 0;text-align: right;" readonly="true" value="0" size="8" ></td>
            <!-- <td></td> -->
        </tr>

        <tr>
            <td colspan="4">Tanda Tangan Pengirim</td>
            <td colspan="4">Tanda Tangan Petugas</td>
            <td colspan="4">Tanda Tangan Pengirim</td>
            <td><label>Biaya Packing</label></td>
            <td>: <input type="text" id = "txt_BiayaPacking" style="border: 0;text-align: right;" readonly="true" value="0"  size="8"></td>
            <!-- <td></td> -->
        </tr>

        <tr>
            <td rowspan="3" colspan="4"></td>
            <td rowspan="3" colspan="4"></td>
            <td rowspan="3" colspan="4"></td>
            <td><?php echo $form->labelEx($model,'OtherFee'); ?></td>
            <td>: <?php echo CHtml::activeNumberField($model,'OtherFee',array('id' => 'txt_OtherFee', 'size'=>8, 'style'=>'text-align: right;', 'value'=>'','tabIndex'=>16)); ?></td>
            <!-- <td><?php //echo $form->error($model,'OtherFee'); ?></td> -->
        </tr>

        <tr>
            <td><label>Biaya Asuransi</label></td>
            <td>: <input type="text" id = "txt_BiayaAsuransi" style="border: 0;text-align: right" readonly="true" value="0" size="8" ></td>
            <!-- <td></td> -->
        </tr>

        <tr>
            <td><label>Biaya Adm Asuransi</label></td>
            <td>: <input type="text" id = "txt_AdmAsuransi" style="border: 0;text-align: right" readonly="true" value="0" size="8" ></td>
        </tr>

        <tr>
            <td colspan="4">(Nama Jelas / Stempel)</td>
            <td colspan="4">(Nama Jelas)</td>
            <td colspan="4">(Nama Jelas / Stempel)</td>
            <td><?php echo $form->labelEx($model,'TotalAmount'); ?></td>
            <td>: <?php echo CHtml::activeNumberField($model,'TotalAmount',array('id' => 'txt_TotalAmount', 'style'=>'text-align: right', 'size'=>8, 'readonly'=>'true')); ?></td>
            <!-- <td><?php //echo $form->error($model,'TotalAmount'); ?></td> -->
        </tr>
    </table>

<table>
    <tr>
        <td><?php echo $form->labelEx($model,'ItemShippingTypeID'); ?></td>
        <td>
            <?php
            $arrSType = Masteritemshippingtype::model()->findAll("isActive = 1");
            $dSType = array();
            $dSType['SELECT'] = 'SELECT';
            foreach ($arrSType as $st){
                $dSType[$st->ItemShippingTypeID] = $st->ItemShippingTypeName;
            }
            echo CHtml::activeDropDownList($model, 'ItemShippingTypeID', $dSType, array('id'=> 'cb_ItemShippingTypeID', 'style'=>'width: 150px','tabIndex'=>17,));
            ?>
        </td>
        <td><?php echo $form->error($model,'ItemShippingTypeID'); ?></td>
    </tr>
    <tr>
        <td><?php echo $form->labelEx($model,'ItemPackingID'); ?></td>
        <td>
            <?php
                $arrPack = Masterpacking::model()->findAll("isActive = 1");
                $dPack = array();
                $dPack['SELECT'] = 'SELECT';
                foreach ($arrPack as $p){
                    $dPack[$p->PackingID] = $p->PackingName;
                }
                echo CHtml::activeDropDownList($model, 'ItemPackingID', $dPack, array('id'=> 'cb_ItemPackingID', 'style'=>'width: 150px','tabIndex'=>17,));
            ?>
        </td>
        <td><?php echo $form->error($model,'ItemPackingID'); ?></td>
    </tr>
    <tr>
        <td><?php echo $form->labelEx($model,'InsuranceNumber'); ?></td>
        <td>
            <?php
                $arrIns = Insprograms::model()->findAll("isActive = 1");
                $dIns = array();
                $dIns['SELECT'] = 'SELECT';
                foreach ($arrIns as $ins){
                    $dIns[$ins->InsuranceNumber] = $ins->InsuranceName;
                }
                echo CHtml::activeDropDownList($model, 'InsuranceNumber', $dIns, array('id'=> 'cb_InsuranceNumber', 'style'=>'width: 150px','tabIndex'=>17,));
            ?>
        </td>
        <td><?php echo $form->error($model,'InsuranceNumber'); ?></td>
    </tr>
    <tr>
        <td><?php echo $form->labelEx($model,'ShippingDistance'); ?></td>
        <td>: <?php echo CHtml::activeNumberField($model,'ShippingDistance',array('id' => 'txt_ShippingDistance', 'size'=>11,'tabIndex'=>23)); ?></td>
        <td><?php echo $form->error($model,'ShippingDistance'); ?></td>
    </tr>
    <td colspan="3">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('tabIndex'=>24)); ?>
    </td>
</tr>
</table>

<?php $this->endWidget(); ?>
</div>
<!-- form -->
